Association Table Mapping
Inheritance
Concrete Table Inheritance
Object Relational Structure Patterns
Chapter 12 of PEAA
How to keep 1-to-1 correspondance between in-memory objects and in-DB objects.
meaningful vs. meaningless key
Simple vs. Compound key
private Object
[] fields
;
public boolean equals
(Object obj
) {
if (!(obj instanceof
Key)) return false;
Key otherKey
= (Key) obj
;
if (this
.fields
.length
!= otherKey
.fields
.length
) return false;
for (int i
= 0; i
< fields
.length
; i
++)
if (!this
.fields
[i
].equals
(otherKey
.fields
[i
])) return false;
return true;
}
Table unique vs. Database unique
Common operations
- Equality Checking
- New key
Representing the Identity Field in an Object
It's tricky for compound keys
Getting a new Key
- Auto-generated
- Database counter
- GUID (Globally Unique IDentifier)
- own ID (table scan or use key table)
1-1

1-n

What to do when we update?
- Delete/Insert
- Back Pointer (put a pointer in both objects)
- Diff the Collection
When?
- A dependent must have exactly one owner.
- There must be no references from any object other than the owner to the dependent

Maps an object into several fields of another object's table
Examples
Money object, Date Range
Saving reference objects as embedded value?
Do it if it does not have any outside meaning
two waya to store: s a binary (BLOB) or as textual characters (CLOB).

Represents an inheritance hierarchy of classes as a single table that has columns for all the fields of the various classes.
Pros
- Only a single table
- No Joins
- Resistant against small changes
Cons
- Confusing with irrelevant fields
- Waste of space

Represents an inheritance hierarchy of classes with one table for each class.
Pros
Space efficiency, column relevance

Represents an inheritance hierarchy of classes with one table per concrete class in the hierarchy.
Chapter 11 of Symfony book
Declare Helper
<?php use_helper('Javascript') ?>
JS in Templates
<?php echo javascript_tag
("
function foobar()
{
...
}
") ?>
=> <script type="text/javascript">
//<![CDATA[
function foobar()
{
...
}
//]]>
</script>
href tag
<?php echo link_to_function
('Click me!', "alert('foobar')") ?>
=> <a href="#" onClick="alert('foobar'); return none;">Click me!</a>
update an element
<div id="indicator">Data processing beginning</div>
<?php echo javascript_tag
(
update_element_function
('indicator', array(
'content' => "<strong>Data processing complete</strong>",
))
) ?>
// Insert content just after the 'indicator' element
update_element_function('indicator', array(
'position' => 'after',
'content' => "<strong>Data processing complete</strong>",
));
// Remove the element before the 'indicator', and only if $condition is true
update_element_function('indicator', array(
'action' => $condition ? 'remove' : 'empty',
'position' => 'before',
))
Prototype
node = $('elementID');
// Means the same as
node = document.getElementById('elementID');
// It can also retrieve more than one element at a time
// And in this case the result is an array of DOM elements
nodes = $('firstDiv', 'secondDiv');
Remote Function
<div id="myzone"></div>
<?php echo javascript_tag
(
remote_function
(array(
'update' => 'myzone',
'url' => 'mymodule/myaction',
))
) ?>
AJAX Link
<div id="feedback"></div>
<?php echo link_to_remote
('Delete this post', array(
'update' => 'feedback',
'url' => 'post/delete?id='.$post->getId(),
)) ?>
<div id="emails"></div>
<?php echo link_to_remote
(image_tag
('refresh'), array(
'update' => 'emails',
'url' => '@list_emails',
), array(
'class' => 'ajax_link',
)) ?> Forms
<div id="item_list"></div>
<?php echo form_remote_tag
(array(
'update' => 'item_list',
'url' => 'item/add',
)) ?>
<label for="item">Item:</label>
<?php echo input_tag
('item') ?>
<?php echo submit_tag
('Add') ?>
</form>
Periodic Remote Call
<div id="notification"></div>
<?php echo periodically_call_remote
(array(
'frequency' => 60,
'update' => 'notification',
'url' => '@watch',
'with' => "'param=' + \$F('mycontent')",
)) ?> Parameters
position
<div id="feedback"></div>
<p>Hello, World!</p>
<?php echo link_to_remote
('Delete this post', array(
'update' => 'feedback',
'url' => 'post/delete?id='.$post->getId(),
'position' => 'after',
)) ?>
callbacks (before, after, loading, loaded, success, failure, 404)
<div id="feedback"></div>
<div id="indicator">Loading...</div>
<?php echo link_to_remote
('Delete this post', array(
'update' => 'feedback',
'url' => 'post/delete?id='.$post->getId(),
'loading' => "Element.show('indicator')",
'complete' => "Element.hide('indicator')",
)) ?>
conditional
<div id="feedback"></div>
<?php echo link_to_remote
('Delete this post', array(
'update' => 'feedback',
'url' => 'post/delete?id='.$post->getId(),
'condition' => "$('elementID') == true",
)) ?>
request method
<div id="feedback"></div>
<?php echo link_to_remote
('Delete this post', array(
'update' => 'feedback',
'url' => 'post/delete?id='.$post->getId(),
'method' => 'get',
)) ?>
script
<div id="feedback"></div>
<?php
// If the response of the post/delete action contains JavaScript,
// allow it to be executed by the browser
echo link_to_remote
('Delete this post', array(
'update' => 'feedback',
'url' => 'post/delete?id='.$post->getId(),
'script' => true,
)) ?> Advanced AJAX
Autocompletion, drag and drop, in place edit, sortable list